package org.linlinjava.litemall.wx.service;

import org.linlinjava.litemall.db.domain.LitemallCoupon;
import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.service.LitemallConponUserServiceImpl;
import org.linlinjava.litemall.db.service.LitemallCouponService;
import org.linlinjava.litemall.db.util.CouponConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CouponAssignService {
    @Autowired
    LitemallCouponService couponService;
    @Autowired
    LitemallConponUserServiceImpl couponUserService;

    /**
     * 分配优惠券
     */
   /* public void assignForRegister(Integer userId){
        List<LitemallCoupon> couponList = couponService.queryRegister();
        for(LitemallCoupon coupon:couponList){
            Integer couponId = coupon.getId();

            Integer count = couponUserService.countUserAndCoupon(userId,couponId);
            if(count>0){
                continue;
            }
            Short limit = coupon.getLimit();
            while(limit>0){
                LitemallCouponUser couponUser = new LitemallCouponUser();
                couponUser.setCouponId(couponId);
                couponUser.setUserId(userId);
                Short timeType = coupon.getTimeType();
                if(timeType.equals(CouponConstant.TIME_TYPE_TIME)){
                    couponUser.setStartTime(coupon.getStartTime());
                    couponUser.setEndTime(coupon.getEndTime());
                }else{
                    couponUser.setStartTime(new Date());


                    couponUser.setEndTime(new Date(coupon.getDays()));
                }
                couponUserService.add(couponUser);

                limit--;
            }
        }
    }*/
}
